package com.yw.common.core.db.test.jdbctemplate;

import java.sql.PreparedStatement;
import java.sql.SQLException;

import com.yw.common.core.db.IDBConnection;
import com.yw.common.core.util.DbUtil;


public class JdbcOper implements IJdbcOper{

	@Override
	public <T> T execute(IJdbcCallback<T> callback) {
		IDBConnection conn = DbUtil.getDBConnection();

		
		return callback.execute(conn);
	}

	@Override
	public int executeUpdate(final String sql,final Object[] params) {
		return this.execute(new PreparedStatementCallback<Integer>(){

			@Override
			public Integer execute(PreparedStatement ps) {
				try{
					return ps.executeUpdate();
				}catch(SQLException e){
					e.printStackTrace();
				}
				
				return -1;
			}

			@Override
			public Object[] getParams() {
				
				return params;
			}

			@Override
			public String getSql() {
				
				return sql;
			}
			
		});
	}

}
